package com.huan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huan.VO.ArticleDetailVo;
import com.huan.VO.PageVo;
import com.huan.VO.RoleVo;
import com.huan.domain.ResponseResult;
import com.huan.domain.entity.Article;
import com.huan.domain.entity.Role;
import com.huan.mapper.RoleMapper;
import com.huan.service.RoleService;
import com.huan.utils.BeanCopyUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色信息表(Role)表服务实现类
 *
 * @author makejava
 * @since 2023-06-24 08:35:21
 */
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Override
    public List<String> selectRoleKeyByUserId(Long id) {
        if(id == 1L){
            List<String> roleKeys = new ArrayList<>();
            roleKeys.add("admin");
            return roleKeys;
        }
        //否则查询用户所具有的角色信息
        return getBaseMapper().selectRoleKeyByUserId(id);
    }

    @Override
    public ResponseResult getAllRole(Integer pageNum, Integer pageSize, String roleName, String status) {
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(Role::getRoleName,roleName);
        wrapper.eq(Role::getStatus,status);
        Page<Role> page = new Page<>();
        page.setPages(pageNum);
        page.setSize(pageSize);
        List<Role> list = page(page, wrapper).getRecords();
        List<RoleVo> detailVos = BeanCopyUtil.resultAllVo(list, RoleVo.class);
        PageVo pageVo = new PageVo(detailVos, page.getTotal());
        return ResponseResult.okResult(pageVo);

    }

    @Override
    public ResponseResult changeStatus(RoleVo role) {
        Role role1 = getById(role.getRoleId());
        role1.setStatus(role.getStatus());
        updateById(role1);
        return ResponseResult.okResult();
















    }
}

